<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'月结会员'),
);
//会员列表
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'yuejie_type'=>array(4,5));
	$return['params']=array();
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['level'])){
		$params['level']=intval($_RQ['level']);
		$return['params']['level']=$_RQ['level'];
	}
	if(isset($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_member',$params,array($pindex,$psize),$total,array(),'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			if($item['merchid']){
				$member=model('jy_merch/member')->getdetail($item['merchid'],$item['mid']);
			}else{
				$member=model('core/member')->detail($item['mid'],array('nickname','onemid','credit1','credit2'));
			}
			$item=array_merge($member,$item);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]：
		</br>1、<red>这里只显示月结客户</red>；
		','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'mid','title'=>'MID','type'=>'string'),
			array('name'=>'member','title'=>'基本信息','type'=>'member'),
			array('name'=>'level','title'=>'等级','type'=>'select','options'=>'levels'),
			array('name'=>'groupid','title'=>'分组','type'=>'select','options'=>'groups'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
			array('name'=>'yuejie_endtime','title'=>'月结到期','type'=>'time'),
			array('name'=>'createtime','title'=>'注册时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'check','title'=>'审核'),
		)),
		'search'=>array(
			array('name'=>'level','width'=>15,'title'=>'等级','type'=>'select','options'=>'levels'),
			array('name'=>'storeid','width'=>15,'title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'core/member.get_member/'),
		),
		
	);
	$return['levels']=pdo_getall('jy_weishop_member_level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	//添加默认等级
	$return['levels'][0]=array(
		'id'=>'0',
		'title'=>'默认会员',
		'level'=>0,
		'discount'=>'0',
		'ordermoney'=>'0.00',
		'ordercount'=>'0',
		'status'=>'1',
	);
	$return['groups']=pdo_getall('jy_weishop_member_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['stores']=pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if($post['check']==1){
			$yuejie_type=1;
		}elseif($post['check']==2){
			$yuejie_type=5;
		}else{
			$yuejie_type=4;
		}
		$update=array(
			'yuejie_type'=>$yuejie_type,
		);
		pdo_update('jy_weishop_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('设置成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),array('storeid','id'));
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'审核',
	);
	$htmls['edit']=array(
		array('type'=>'radio','title'=>'审核','name'=>'check','options'=>'check'),
	);
	$return['htmls']=$htmls;
	$return['check']=array('待审核','审核通过','审核不通过');	
	exi($return);
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}